//+------------------------------------------------------------------+
//|                                              Candle Daily DK.mq4 |
//|                                            modifief by Darkkiller|
//|                     Do not know who create this,but thanks to him|
//+------------------------------------------------------------------+
#property copyright ""
#property link      ""

#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
  for (int i=0; i<10; i++) {
    ObjectDelete("BD"+i);
    ObjectDelete("SD"+i);    
  } 
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   if(Period() >= PERIOD_D1) return(0);
   
   double dailyHigh[10], dailyLow[10], dailyOpen[10], dailyClose[10];
         
   ArrayCopySeries(dailyHigh,MODE_HIGH,Symbol(),PERIOD_D1);
   ArrayCopySeries(dailyLow,MODE_LOW,Symbol(),PERIOD_D1);
   ArrayCopySeries(dailyOpen,MODE_OPEN,Symbol(),PERIOD_D1);
   ArrayCopySeries(dailyClose,MODE_CLOSE,Symbol(),PERIOD_D1);

   color cl;
   
   datetime t1;
   datetime t2;
   
   int i,j=5;
   for (i=2;i>=0;i--){
      t1=Time[0]+(Period()*(j*110));
      t2=Time[0]+(Period()*(j+1)*110);
      if(ObjectFind("BD"+i)==-1){
         if (dailyOpen[i]>dailyClose[i]) cl=Red; else cl=Blue;
         CreateObjects("D"+i,t1,t2,dailyOpen[i],dailyClose[i],dailyLow[i],dailyHigh[i],cl);
      }else{
         if (dailyOpen[i]>dailyClose[i]) cl=Red; else cl=Blue;
         DrawObjects("D"+i,t1,t2,dailyOpen[i],dailyClose[i],dailyLow[i],dailyHigh[i],cl);      
      }
      j++;
      j++;
      //Comment(dailyClose[i]);
   }
   
   
   
   return(0);
  }
//+------------------------------------------------------------------+
void CreateObjects(string no, datetime dt1, datetime dt2, double po, double pc, double pl,double ph, color cl) {
  if (po==pc) cl=Gray;
  
  ObjectCreate("B"+no, OBJ_RECTANGLE, 0, dt1,po, dt2, pc);
  ObjectSet("B"+no, OBJPROP_STYLE, STYLE_SOLID);
  ObjectSet("B"+no, OBJPROP_COLOR, cl);
  ObjectSet("B"+no, OBJPROP_BACK, True);
  datetime t=dt1+((dt2-dt1)/2);
  ObjectCreate("S"+no, OBJ_TREND, 0, t, pl, t, ph);
  ObjectSet("S"+no, OBJPROP_COLOR, cl);
  ObjectSet("S"+no, OBJPROP_BACK, true);
  ObjectSet("S"+no, OBJPROP_RAY, False);
  ObjectSet("S"+no, OBJPROP_WIDTH, 2);
}
void DrawObjects(string no, datetime dt1, datetime dt2, double po, double pc, double pl,double ph, color cl) {
  if (po==pc) cl=Gray;
    
  ObjectSet("B"+no, OBJPROP_TIME1 , dt1);
  ObjectSet("B"+no, OBJPROP_PRICE1, po);
  ObjectSet("B"+no, OBJPROP_TIME2 , dt2);
  ObjectSet("B"+no, OBJPROP_PRICE2, pc);
  ObjectSet("B"+no, OBJPROP_BACK, true);
  ObjectSet("B"+no, OBJPROP_COLOR, cl);
  datetime t=dt1+((dt2-dt1)/2);
  ObjectSet("S"+no, OBJPROP_TIME1 , t);
  ObjectSet("S"+no, OBJPROP_PRICE1, pl);
  ObjectSet("S"+no, OBJPROP_TIME2 , t);
  ObjectSet("S"+no, OBJPROP_PRICE2, ph);
  ObjectSet("S"+no, OBJPROP_BACK, true);
  ObjectSet("S"+no, OBJPROP_WIDTH, 2);
  ObjectSet("S"+no, OBJPROP_COLOR, cl);
  
  
}

